package com.atguigu.paymentdemo.task;

import com.atguigu.paymentdemo.entity.OrderInfo;
import com.atguigu.paymentdemo.service.OrderInfoService;
import com.atguigu.paymentdemo.service.WxPayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

@Slf4j
@Component
public class wxPayTask {
    @Resource
    OrderInfoService orderInfoService;
    @Resource
    WxPayService wxPayService;

    /**定时检查数据库中在规定时限内未支付的订单，未支付的订单
     *
     * @throws IOException
     */
    @Scheduled(cron = "0/30 * * * * ?")
    public void orderConfirm() throws IOException {
        //log.info("定时检查数据库中在规定时限内未支付的订单");
        //定时检查数据库中在规定时限内未支付的订单，未支付的订单
        List<OrderInfo> orderInfoList = orderInfoService.getNoPayOrderOvertime(1L);
        for(OrderInfo orderInfo : orderInfoList){
            if(orderInfo == null) log.info("暂无规定时限内未支付的订单");
            //log.info("未支付订单"+ orderInfo.getOrderNo());
            //log.info(orderInfo.getOrderNo()+" 创建时间："+orderInfo.createTime);
            //调用微信支付接口，核实订单状态
            wxPayService.checkOrderStatus(orderInfo);
        }
    }
}
